/**
* Created by ren on 2017/1/11.
*/
<template>
  <div class='dtTqRecord' v-if="goodsData!==''">
    <div class="item" v-for="(item,index) in goodsData.content" @click="todtDetail(item.orderNo,index)">
      <div style="margin-bottom:10px">
        <span>{{item.objectName}}</span>
        <span v-if="item.putinType==='day'"> 日定投</span>
        <span v-if="item.putinType==='month'">月定投</span>
        <span v-if="item.putinType==='week'">周定投</span>
        <span v-if="item.putinType==='year'">年定投</span>
      </div>
      <div style="color:#999999">{{item.createTime.substring(0,10)}}</div>
      <img src="../../assets/toright.png" style="float:right;margin-top:-40px">
      <span style="float:right;margin-top: -37px;margin-right: 35px;color:#ff9900;">已提取</span>
    </div>
    <div class="paging-wrap">
      <div class="paging" v-if="goodsData!==''&&goodsData.totalPages>1">
        <img src="../../assets/prev.png" style="float: left;margin-top: 23px;cursor: pointer" @click="prev">
        <div class="page" style="float: left">
          <div v-for="(item,index) in goodsData.totalPages" v-if="goodsData.totalPages<9"
               :class="{active:index===nextPage}" @click="paging(index)">{{index+1}}
          </div>
          <template v-if="goodsData.totalPages>8">
            <template v-if="goodsData.totalPages-9<nextPage">
              <div v-for="(item,index) in goodsData.totalPages" v-if="index>goodsData.totalPages-9"
                   :class="{active:index===nextPage}" @click="paging(index)">{{index+1}}
              </div>
            </template>
            <template v-else>
              <div v-for="(item,index) in goodsData.totalPages" v-if="index<5+nextPage&&index>nextPage-1"
                   :class="{active:index===nextPage}"
                   @click="paging(index)">{{index+1}}
              </div>
              <div>……</div>
              <div v-for="(item,index) in goodsData.totalPages" v-if="index>goodsData.totalPages-3"
                   :class="{active:index===nextPage}" @click="paging(index)">{{index+1}}
              </div>
            </template>
          </template>
        </div>
        <img src="../../assets/next.png" style="float: left;margin-top: 23px;cursor: pointer" @click="next">
        <div class="total">共{{goodsData.totalPages}}页</div>
      </div>
    </div>
    <Notify :parentThis='this'></Notify>
  </div>
</template>

<script>
  import API from '../../api'
  import Notify from '../Notify'
  export default {
    name: 'dtTqRecord',
    components: {
      Notify
    },
    data: function () {
      return {
        nextPage: 0,
        goodsData: '',
        notifyStatus: 2
      }
    },
    props: ['parentThis'],
    methods: {
      paging: function (page) {
        this.nextPage = page
        this.extractRecord()
      },
      prev: function () {
        if (this.nextPage > 0) {
          this.nextPage = this.nextPage - 1
          this.extractRecord()
        }
      },
      next: function () {
        if (this.nextPage < this.goodsData.totalPages - 1) {
          this.nextPage = this.nextPage + 1
          this.extractRecord()
        }
      },
      extractRecord: function () {
        this.$http.post(API.extractRecord, {
          userId: this.$cookie.get('id'),
          nextPage: this.nextPage,
          pageSize: 5,
          type: this.parentThis.cutName === 'jsj' ? 1 : 3
        }).then((ret) => {
          const result = ret.body
          if (result.code === 1) {
            this.goodsData = result.object
          } else {
            this.notifyStatus = '0|' + result.message
          }
        }, (err) => {
          console.log(err)
        })
      },
      todtDetail: function (orderNo, index) {
        this.$cookie.set('dttqRecord', JSON.stringify(this.goodsData.content[index]))
        this.$router.push({name: 'dtDetail', params: {dtId: orderNo}})
      }
    },
    mounted: function () {
      this.extractRecord()
    }
  }
</script>